﻿using System.Linq;
using System.Web.Mvc;
using API.Helpers;
using API.IServices;
using API.Services;
using POS.Models;

namespace POS.Controllers
{
    public class DrinkOrderController : BaseController
    {
        //
        // GET: /DrinkOrder/

        public ActionResult Index()
        {
            return View();
        }

        private readonly IDrinkService _drinkService = DependencyInjectionHelper.Resolve<IDrinkService>();
        private readonly IDrinkOrderService _drinkOrderService = DependencyInjectionHelper.Resolve<IDrinkOrderService>();

        public DrinkOrderController()
        {
            _drinkService = new DrinkService();
            _drinkOrderService = new DrinkOrderService();
        }

        [HttpGet]
        public JsonNetResult GetDrinkOrderListing(string sort)
        {
            var query = _drinkOrderService.Get().OrderByDescending(c => c.Created).Where(c => c.TableOrder.WaiterId == WaiterId);
            var count = query.Count();

            //if (sort != null)
            //{
            //    var sortData = new System.Web.Script.Serialization.JavaScriptSerializer().Deserialize<List<ExtJsSortParameter>>(sort).First();
            //    query = query.OrderBy(String.Format("{0} {1}", sortData.Property, sortData.Direction.ToLower()));
            //}
					
            return new JsonNetResult(new
            {
                Data = query.ToList(),
                TotalRecords = count
            });
        }

    }
}
